
using System.Collections.Generic;
using UnityEngine;
using Framework.UI;

namespace Framework.Scene {
    public sealed class SceneManager : FrameworkModule
    {
        public string LoadSceneUIPath { get; set; } = null;
        public ILoadingPanel LoadingPanel { get; private set; }
        public AsyncOperation LoadOperation { get; private set; }

        public override int Priority { get { return 60; }}

        public BaseScene Scene { get; set; }

        public void LoadScene(string sceneAssetName)
        {
            this.LoadSceneAsync(sceneAssetName).Coroutine();
        }

        public async FTask LoadSceneAsync(string sceneAssetName)
        {
            LoadingPanel = await FrameworkEntry.GetModule<UI.UIManager>().OpenUI(this.LoadSceneUIPath) as ILoadingPanel;
            this.LoadOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneAssetName);
            LoadingPanel.StartLoading(this.LoadOperation);
        }

        public void CloseLoadingPanel()
        {
            if (LoadingPanel != null)
            {
                LoadingPanel.Close();
                LoadingPanel = null;
            }
        }
    }
}